package com.ynrcc.util;

import java.io.File;

import com.eova.config.EovaInit;

public class MigrateDoc {

	public static void main(String[] args) {
		EovaInit.initConfig();
		String basedir = "D:\\OneDrive\\09 file\\sample\\";
		// String sourceId = "0FA3BCB7C843449EC8257837000F0A56";
		String brchcd = "0199990000";
		int total = 0, success = 0, fail = 0;

		if (ConnDB.connDB())
			System.out.println("数据库连接成功！");
		else {
			System.out.println("数据库连接失败，返回！");
		}

		File baseFolder = new File(basedir);
		String[] files = baseFolder.list();
		
		// 档案主表
		total = files.length;
		for (String sourceId : files) {
			if (ImportMain.importMain(basedir, sourceId, brchcd)) {
				success++;
				System.out.println("导入成功");
			} else {
				fail++;
				System.out.println("导入失败，请查找具体原因！");
			}
		}

		System.out.println("----------");
		System.out.println("[档案主表]导入完成，共[" + total + "],成功[" + success + "],失败[" + fail + "]");

		// 处理收文处理单
		success = 0;
		fail = 0;
		total = files.length;
		for (String sourceId : files) {
			if (ImportSw.importSw(basedir, sourceId, brchcd)) {
				success++;
				System.out.println("导入成功");
			} else {
				fail++;
				System.out.println("导入失败，请查找具体原因！");
			}
		}
		System.out.println("----------");
		System.out.println("[收文处理单]导入完成，共[" + total + "],成功[" + success + "],失败[" + fail + "]");

		// 处理发文处理单
		success = 0;
		fail = 0;
		total = files.length;
		for (String sourceId : files) {
			if (ImportFw.importFw(basedir, sourceId, brchcd)) {
				success++;
				System.out.println("导入成功");
			} else {
				fail++;
				System.out.println("导入失败，请查找具体原因！");
			}
		}
		System.out.println("----------");
		System.out.println("[发文处理单]导入完成，共[" + total + "],成功[" + success + "],失败[" + fail + "]");
		
		//处理文件
		success = 0;
		fail = 0;
		total = files.length;
		for (String sourceId : files) {
			if (ImportWj.importWj(basedir, sourceId, brchcd)) {
				success++;
				System.out.println("导入成功");
			} else {
				fail++;
				System.out.println("导入失败，请查找具体原因！");
			}
		}
		System.out.println("----------");
		System.out.println("[文件]导入完成，共[" + total + "],成功[" + success + "],失败[" + fail + "]");
	}
}
